package com.UnionPayCenter.operation.enums;

import com.UnionPayCenter.enums.CodeBaseEnum;
import com.UnionPayCenter.enums.ErrorCodeEnum;
import com.UnionPayCenter.exception.ApiException;

/**
 * 运营活动错误码枚举
 */
public enum ActivityErrorCodeEnum implements CodeBaseEnum {


    ACTIVITY_TYPE_NOT_EXIST(54001, "活动类型不存在"),
    ACTIVITY_EXISTED(54002, "只能创建一个活动"),
    ;


    private int code;

    private String msg;

    /**
     * Msg string.
     *
     * @return the string
     */
    public String msg() {
        return msg;
    }

    /**
     * Code int.
     *
     * @return the int
     */
    public int code() {
        return code;
    }

    public void exception() {
        throw new ApiException(code, msg);
    }

    ActivityErrorCodeEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * Gets enum.
     *
     * @param code the code
     * @return the enum
     */
    public static ErrorCodeEnum getEnum(int code) {
        for (ErrorCodeEnum ele : ErrorCodeEnum.values()) {
            if (ele.code() == code) {
                return ele;
            }
        }
        return null;
    }
}
